package com.sino.operation.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sino.operation.commons.response.CenterResponseEntity;
import com.sino.operation.entity.AutoCheck;
import com.sino.operation.service.AutoCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("autoCheckManager")
@Api(value = "自动校验配置管理",tags="自动校验配置管理")
public class AutoCheckManagerController {
@Autowired
    private AutoCheckService autoCheckService;

    @GetMapping("/selectAutoCheckList")
    @ApiOperation(value = "查询校验列表")
    @ResponseBody
    public IPage<AutoCheck> getCenterList(@RequestParam Map<String,String> map){
        IPage<AutoCheck> autoCheckIPage = autoCheckService.selectList(map);
        return autoCheckIPage;
    }

    @PostMapping("/addAutoCheck")
    @ApiOperation(value = "新增自动校验")
    @ResponseBody
    public CenterResponseEntity addTeller(AutoCheck autoCheck){
        try {
            autoCheckService.saveOrUpdate(autoCheck);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CenterResponseEntity.build();
    }

    @PostMapping("/deleteAutoCheck")
    @ApiOperation(value = "批量删除自动校验")
    @ResponseBody
    public CenterResponseEntity deleteAutoCheck(List ids){
        try {
            autoCheckService.removeByIds(ids);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build();
    }

    @GetMapping("/selectAutoCheckById")
    @ApiOperation(value = "根据ID校验数据")
    @ResponseBody
    public CenterResponseEntity selectAutoCheckById(@RequestParam String id){
        AutoCheck autoCheck=null;
        try {
            autoCheck = autoCheckService.getById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build(AutoCheck.class).setData(autoCheck);
    }
    @PostMapping("/updateAutoCheck")
    @ApiOperation(value = "修改自动校验")
    @ResponseBody
    public CenterResponseEntity updateAutoCheck(AutoCheck autoCheck){
        try {
            autoCheckService.saveOrUpdate(autoCheck);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build();
    }
}
